package org.intrasearch.spider;

import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;

import java.net.URL;

/**
 * PATISDG 11.11.2009
 */
public class VirtualFileSmbImpl implements VirtualFile
{
    private final SmbFile smbFile;

    VirtualFileSmbImpl(SmbFile smbFile)
    {
        this.smbFile = smbFile;
    }

    public VirtualFile[] listFiles()
    {
        try
        {
            SmbFile[] files = smbFile.listFiles();
            VirtualFile[] virtualFiles = new VirtualFile[files.length];
            int i = 0;
            for (SmbFile file : files)
            {
                virtualFiles[i++] = new VirtualFileSmbImpl(file);
            }
            return virtualFiles;
        }
        catch (SmbException e)
        {
            throw new RuntimeException(e);
        }
    }

    public boolean isFile()
    {
        try
        {
            return smbFile.isFile();
        }
        catch (SmbException e)
        {
            throw new RuntimeException(e);
        }
    }

    public long length()
    {
        try
        {
            return smbFile.length();
        }
        catch (SmbException e)
        {
            throw new RuntimeException(e);
        }
    }

    public boolean isDirectory()
    {
        try
        {
            return smbFile.isDirectory();
        }
        catch (SmbException e)
        {
            throw new RuntimeException(e);
        }
    }

    public URL getURL()
    {
        return smbFile.getURL();
    }

    public String getName()
    {
        return smbFile.getName();
    }

    @Override
    public String toString()
    {
        return smbFile.getUncPath();
    }

    SmbFile getSmbFile()
    {
        return smbFile;
    }
}
